/**
 * @author tibi
 */

 function paintGrid(node, event){
 	//alert(node.id);
 	Ext.Ajax.request({
					url: 'server/EntityItems.php?__id='+node.id,
					success: function(response) {
						entityId = id;
						r = response.responseText;
						//alert(r);
						var gridDefinition = eval(r);
						gridColumns = eval(gridDefinition[0]);
						myData = eval(gridDefinition[1]);
						
						var storeDef = eval(gridDefinition[2]);
						
						//alert(gridColumns);
						store = new Ext.data.SimpleStore({
							fields: storeDef
						});
						store.loadData(myData);
						
						grid = new Ext.grid.GridPanel({
							id: node.id,
							store: store,
							columns: gridColumns,
							trackMouseOver: true,
							
							selModel: new Ext.grid.RowSelectionModel({singleSelect:true}),
							emptyText: "Nu exista date introduse pentru aceasta entitate",
							title: node.text
						});
						grid.addListener('rowcontextmenu', renderMenu)
						grid.closable = true;
						AppTabPanel.add(grid);
						//tab.doLayout();
						AppTabPanel.setActiveTab(grid.id);
					}
				});	
 }
 
 
 function repaintGrid(node, event){
 	Ext.Ajax.request({
					url: 'server/EntityItems.php?__id='+node.id,
					success: function(response) {
						entityId = node.id;
						r = response.responseText;
						//alert(r);
						var gridDefinition = eval(r);
						gridColumns = eval(gridDefinition[0]);
						myData = eval(gridDefinition[1]);
						
						var storeDef = eval(gridDefinition[2]);
						
						//alert(gridColumns);
						store = new Ext.data.SimpleStore({
							fields: storeDef
						});
						store.loadData(myData);
						
						grid = new Ext.grid.GridPanel({
							id: node.id,
							store: store,
							columns: gridColumns,
							trackMouseOver: true,
							
							selModel: new Ext.grid.RowSelectionModel({singleSelect:true}),
							emptyText: "Nu exista date introduse pentru aceasta entitate",
							title: node.text
						});
						grid.addListener('rowcontextmenu', renderMenu)
						grid.render();
					}
				});	
 }